//
//  CORightMessageCell.swift
//  KOLHub
//
//  Created by Ruthless on 2023/7/27.
//

import UIKit

class CORightMessageCell: UITableViewCell {
    // MARK: - Property
    var model: COSendMessageModel? {
        didSet {
            guard let model = model else { return }
            
//            avatar.sd_setImage(with: URL(string: model.avatar ))
            avatar.kf.setImage(with: URL(string: model.avatar))
            
            contentLabel.text = model.content
            
        }
    }
    // MARK: - init
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        selectionStyle = .none
        configUI()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    // MARK: - UI
    private func configUI() {
        backgroundColor = .clear
        
        contentView.addSubview(avatar)
        contentView.addSubview(bgView)
        contentView.addSubview(contentLabel)
        
        avatar.snp.makeConstraints { make in
            make.right.equalToSuperview().offset(-15)
            make.top.equalToSuperview().offset(0)
            make.width.height.equalTo(40)
        }
        
        bgView.snp.makeConstraints { make in
            make.right.equalTo(avatar.snp.left).offset(-10)
            make.top.equalToSuperview().offset(0)
            make.left.equalTo(contentLabel.snp.left).offset(-18)
            make.bottom.equalTo(contentLabel.snp.bottom).offset(10)
            make.width.lessThanOrEqualTo(172)
            make.bottom.equalToSuperview().offset(0)
        }
        
        contentLabel.snp.makeConstraints { make in
            make.right.equalTo(bgView.snp.right).offset(-18)
            make.top.equalTo(bgView.snp.top).offset(10)
        }
    }
    // MARK: - lazy load
    private lazy var avatar: UIImageView = {
        let imgV = UIImageView()
        imgV.layer.masksToBounds = true
        imgV.layer.cornerRadius = 20
        return imgV
    }()
    
    private lazy var bgView: UIView = {
        let view = UIView()
        view.backgroundColor = .rgba(254, 107, 117, 1)
        view.layer.masksToBounds = true
        view.layer.cornerRadius = 15
//        view.layer.maskedCorners = [.layerMinXMinYCorner, .layerMinXMaxYCorner]
        return view
    }()
    
    private lazy var contentLabel: UILabel = {
        let label = UILabel()
        label.font = .medium(15)
        label.textColor = .white
        label.numberOfLines = 0
        return label
    }()
}
